package com.zw.sample;

public class CacheTest {
	public static void main(String[] args) {
		int arraySizes[] = new int[]{1024 , 1024 * 1, 1024 * 2, 1024 * 3, 1024 * 4, 
				1024 * 5, 1024 * 6, 1024 * 7, 1024 * 8, 1024 * 9, 1024 * 10, 
				1024 * 16, 1024 * 32, 1024 * 64, 1024 * 128, 1024 * 256, 1024 * 512,
				1024 * 1024, 1024 * 2048};
		for (int p = 0; p < arraySizes.length; p++) {
			int arr[] = new int[arraySizes[p]];
			int steps = 64 * 1024 * 1024; // Arbitrary number of steps
			int lengthMod = arr.length - 1;
			long time = System.currentTimeMillis();
			for (int i = 0; i < steps; i++)
			{
			    arr[(i * 16) & lengthMod]++; // (x & lengthMod) is equal to (x % arr.Length)
			}
			System.out.println("Size is : " + (arraySizes[p] / 1024 * 4) + "kb; use time " + (System.currentTimeMillis() - time));
		}
	}
}
